
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>Title</title>
    <link rel="stylesheet" href="/css/bootstrap.min.css">
    <script src="/js/jquery/jquery.min.js"></script>
    <script src="/js/jquery.validation/1.14.0/jquery.validate.min.js"></script>
    <script src="/js/jquery.validation/1.14.0/messages_zh.min.js"></script>
    <style>
        input.error{
            border: 1px solid #E6594E;
        }
    </style>
</head>
<body>
<div class="container">

    <form id="editUserForm">
        <br/>
        <div class="form-group">
            <label for="bname">书籍名称：</label>
            <input type="text" class="form-control" id="bname" name="bname" value="${book.bname}" placeholder="输入书名">
        </div>
        <div class="form-group">
            <label for="author">作者：</label>
            <input type="text" class="form-control" id="author" name="author" value="${book.author}" placeholder="输入作者">
        </div>
        <div class="form-group">
            <label for="publ">出版社：</label>
            <input type="text" class="form-control" id="publ" name="publ" value="${book.publ}" placeholder="输入出版社">
        </div>
        <div class="form-group">
            <button type="button" id="editBtn" class="btn btn-success">修改</button>
            <button type="button" id="cancelBtn" class="btn btn-default">取消</button>
        </div>
    </form>
</div>
<script>
    //交互传值
    var editBooks = function () {
        if (!check().form()) {
            return;
        }
        $.ajax({
            type: "POST",
            url: "yc_updateBooks_nb",
            dataType: "json",
            data: {
                bname: $("#bname").val(),
                author: $("#author").val(),
                publ: $("#publ").val(),
                bid:${bid}
            },
            success: function (msg) {
                parent.layer.msg("已成功编辑!", {icon: 6});
                $("#cancelBtn").click();

            }
        });
    };
    //调用方法修改操作
    $("#editBtn").click(function () {
        editBooks();
    });
    //关闭
    $("#cancelBtn").click(function () {
        var index = parent.layer.getFrameIndex(window.name);
        parent.getall();
        parent.layer.close(index);
    });

    //校验字段是否正确
    function check() {
        return $("#editUserForm").validate({
            rules: {
                bname: {
                    required: true
                },
                author: {
                    required: true
                },
                publ: {
                    required: true
                }
            },
            messages: {
                bname: {
                    required: ""
                },
                author: {
                    required: ""
                },
                publ: {
                    required: ""
                }
            }
        });
    }

</script>

</body>
</html>
